/**
 * FileName: LoginController
 * Author: Mr.Wang
 * Date: 2025/10/15 13:44
 * Description:
 * History:
 */
package org.test.device.controller;

import com.alibaba.fastjson2.JSON;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.test.device.params.LoginParam;
import org.test.device.params.RefreshTokenParam;
import org.test.device.service.LoginService;
import org.test.device.utils.ResultData;

/**
 * 〈一句话功能简述〉<br>
 * 〈登录控制器〉
 *
 * @author Mr.Wang
 * @create 2025/10/15
 * @since 1.0.0
 */
@Slf4j
@Tag(name = "登录接口", description = "登录相关接口")
@RestController
@RequestMapping("/auth")
public class LoginController {

    @Autowired
    LoginService loginService;

    /**
    * @Author Mr.Wang
    * @Description 登录接口
    * @Date  2025/10/17
    * @Param loginParams 登录参数
    **/
    @PostMapping("/login")
    public ResultData login(@RequestBody LoginParam loginParams) {
        log.info("登录参数：{}", JSON.toJSONString(loginParams));
        return loginService.login(loginParams.getUsername(), loginParams.getPassword());
    }


    /**
    * @Author Mr.Wang
    * @Description 刷新token接口
    * @Date  2025/10/17
    * @Param param 刷新token参数
    **/
    @PostMapping("/refreshToken")
    public ResultData refreshToken(@RequestBody RefreshTokenParam param) {
        log.info("刷新token参数：{}", JSON.toJSONString(param));
        return loginService.refreshToken(param);
    }

    /**
    * @Author Mr.Wang
    * @Description 退出登录接口
    * @Date  2025/10/17
    * @Param userId 用户ID
    **/
    @PostMapping("/logout")
    public ResultData logout(Long userId) {
        log.info("退出登录参数：{}", userId);
        return loginService.logout(userId);
    }
}